<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>6 封装 hasPubProperty 实现判断属性是否是当前对象自己的属性</title>
</head>

<body>
  <script>
    function hasPubProperty(obj, attr) {
      let message = "";
      if (attr in obj) {
        if (obj.hasOwnProperty(attr)) {
          message = `${attr}是${obj.name}对象的一个私有属性或方法`;
        } else {
          message = `${attr}是${obj.name}对象的一个公共属性或方法，不是一个私有属性或方法`;
        }
      } else {
        message = `${attr}不是${obj.name}对象的公共/私有属性或方法`;
      }
      return message;
    }

    let obj = {
      name: "Henry",
      age: 22,
      say: function () { },
    }

    let res = hasPubProperty(obj, "valueOf")

    console.log(res)
  </script>
</body>

</html>